home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Applications / ircle 1.5.1 / source / ircle sources / IRCNComm.p < prev    next >
Encoding:
Text File  |  1993-10-30  |  8.6 KB  |  343 lines  |  [TEXT/PJMM]

  1. {    ircle - Internet Relay Chat client    }
  2. {    File: IRCNComm    }
  3. {    Copyright © 1992 Olaf Titz (s_titz@ira.uka.de)    }
  4.  
  5. {    This program is free software; you can redistribute it and/or modify    }
  6. {    it under the terms of the GNU General Public License as published by    }
  7. {    the Free Software Foundation; either version 2 of the License, or    }
  8. {    (at your option) any later version.    }
  9.  
  10. {    This program is distributed in the hope that it will be useful,    }
  11. {    but WITHOUT ANY WARRANTY; without even the implied warranty of    }
  12. {    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    }
  13. {    GNU General Public License for more details.    }
  14.  
  15. {    You should have received a copy of the GNU General Public License    }
  16. {    along with this program; if not, write to the Free Software    }
  17. {    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    }
  18.  
  19. unit IRCNComm;
  20. { Handles numeric server messages. }
  21.  
  22. interface
  23. uses
  24.     TCPTypes, TCPStuff, TCPConnections, ApplBase, MiscGlue, MsgWindows, {}
  25.     IRCGlobals, IRCAux, IRCChannels, IRCNotify, IRCCommands;
  26.  
  27. function NumericComm (comm: integer; var from, target, rest: string): boolean;
  28. { Handles numeric message comm with arguments from, target, rest }
  29.  
  30. implementation
  31.  
  32. function NumericComm (comm: integer; var from, target, rest: string): boolean;
  33.     var
  34.         s: string;
  35.         s1, s2, s3, s4: string[80];
  36.         l: longint;
  37.         i: integer;
  38.         c: char;
  39.     begin
  40.         NumericComm := true;
  41. { Numerics and their meanings taken originally from IRCII 2.1.something. }
  42. { Adapted to RFC 1459 with many additions… }
  43. { Where there are different formats for 2.6/2.7, this will work with 2.7 as tested. }
  44. { Some 2.8 messages found by experimentation }
  45. { Here messages are sorted by type }
  46.         case comm of
  47.  
  48. { generic line }
  49.             251, 255, { new LUSERS reply }
  50.             305, 306, { AWAY confirmation }
  51.             342, { SUMMON confirmation }
  52.             364, { new LINKS reply }
  53.             371, { new INFO reply }
  54.             372, 375, { new MOTD }
  55.             391, { TIME reply }
  56.             395: { nobody logged in }
  57.                 LineMsg(rest);
  58.  
  59. { generic line with from field }
  60.             200..209, 261, 212..218, 241..244, { TRACE/STATS info }
  61.             302, { new USERHOST reply }
  62.             382: { Rehash }
  63.                 if not flushing then begin
  64.                     s := concat(from, ': ', rest);
  65.                     LineMsg(s)
  66.                 end;
  67.  
  68. { generic error or important message }
  69.             1, 3, { 2.8 intro }
  70.             256..259, { new ADMIN reply }
  71.             381, { Operator status }
  72.             401..414, { no such nick/server/channel; cannot send }
  73.             421, { unknown command }
  74.             431, 432, 436, { bogus nick }
  75.             442, { not on channel }
  76. { 461 need passwd for OPER? }
  77.             461, { need more parameters }
  78.             462, { registration problems }
  79.             467, { Channel key set }
  80.             481..483: { no privileges }
  81.                 begin
  82.                 if rest[1] = ':' then
  83.                     delete(rest, 1, 1);
  84.                 s := concat('*** ', rest);
  85.                 LineMsg(s);
  86.             end;
  87.  
  88. { generic error with from field }
  89.             422..424, { Server config error }
  90.             444..446, { SUMMON/USERS failed }
  91.             465, { Banned }
  92.             471..475, { Cannot join/ set mode }
  93.             491, { No O-line }
  94.             501, 502, { Bad usermode }
  95.             331: { Topic bogosity }
  96.                 begin
  97.                 s := concat('*** (', from, ') ', rest);
  98.                 LineMsg(s)
  99.             end;
  100.  
  101. { Status information }
  102.             4: { 2.8 server telling its name, version etc }
  103.                 begin
  104.                 NextArg(rest, s1);
  105.                 CurrentServer := s1;
  106.                 NextArg(rest, s1);
  107.                 if copy(s1, 1, 3) = '2.8' then
  108.                     serverVersion := SV_28
  109.                 else begin
  110.                     s := concat('*** Server version is unknown to client: ', s1);
  111.                     LineMsg(s)
  112.                 end;
  113.                 NextArg(rest, s1);
  114.                 UpdateStatusLine;
  115.                 s := concat('Mode flags for users are: ', s1, '; for channels are: ', rest);
  116.                 LineMsg(s)
  117.             end;
  118.             301:  { user is away }
  119.                 begin
  120.                 NextArg(rest, s1);
  121.                 s := concat(s1, ' is away (', rest, ')');
  122.                 Message(s)
  123.             end;
  124.             324: { Mode }
  125.                 begin
  126.                 NextArg(rest, s1);
  127.                 if length(rest) > 1 then
  128.                     if (length(rest) > 2) or (rest[2] <> ' ') then begin
  129.                         s := concat('Mode is ', rest);
  130.                         ChannelMsg(s1, s);
  131.                     end
  132.             end;
  133.             332: { Topic }
  134.                 begin
  135.                 s := concat('Topic is: ', rest);
  136.                 Message(s)
  137.             end;
  138.             221: { user mode }
  139.                 begin
  140.                 s := concat('User mode is: ', rest);
  141.                 Message(s)
  142.             end;
  143.  
  144.  
  145. { Verbose command replies }
  146.             211: { STATS L reply }
  147.                 begin
  148.                 NextArg(rest, s1);
  149.                 s := concat('**', s1, '**');
  150.                 LineMsg(s);
  151.                 s := '';
  152.                 for i := 1 to 5 do begin
  153.                     NextArg(rest, s1);
  154.                     s := stringof(s, s1 : 12);
  155.                 end;
  156.                 s := concat(s, ' ', rest);
  157.                 LineMsg(s)
  158.             end;
  159.             252..254: { new LUSERS numbers }
  160.                 begin
  161.                 NextArg(rest, s1);
  162.                 s := concat('There are ', s1, ' ', rest);
  163.                 LineMsg(s);
  164.             end;
  165.             303: { ISON reply }
  166.                 IsonReply(rest);
  167.             352:  { new WHO reply }
  168.                 if not flushing then begin
  169.                     NextArg(rest, s1);
  170.                     if s1 <> 'Channel' then begin
  171.                         NextArg(rest, s2);
  172.                         NextArg(rest, s3);
  173.                         s2 := concat(s2, '@', s3);
  174.                         NextArg(rest, s3);
  175.                         NextArg(rest, s3);
  176.                         NextArg(rest, s4);
  177.                         s := StringOf(s1 : 10, ' ', s3 : 9, s4 : 4, '  ', s2, ' (', rest, ')');
  178.                         ChannelMsg(s1, s)
  179.                     end;
  180.                 end;
  181.             353: { new NAMES reply }
  182.                 if showNAMES and (not flushing) then begin
  183.                     s := copy(rest, 3, 255);
  184.                     i := pos(' ', s);
  185.                     s1 := copy(s, 1, i - 1);
  186.                     ChannelMsg(s1, s)
  187.                 end;
  188.             311: { whois name info }
  189.                 begin
  190.                 NextArg(rest, s1);
  191.                 NextArg(rest, s2);
  192.                 NextArg(rest, s3);
  193.                 s := concat(s1, ' is ', s2, '@', s3, ' (', copy(rest, 4, 255), ')');
  194.                 Message(s)
  195.             end;
  196.             314: { whowas name info }
  197.                 begin
  198.                 NextArg(rest, s1);
  199.                 NextArg(rest, s2);
  200.                 NextArg(rest, s3);
  201.                 s := concat(s1, ' was ', s2, '@', s3, ' (', copy(rest, 4, 255), ')');
  202.                 Message(s)
  203.             end;
  204.             313: { whois operator }
  205.                 begin
  206.                 NextArg(rest, s1);
  207.                 s := concat(s1, ' ', rest);
  208.                 Message(s)
  209.             end;
  210.             319: { whois channels }
  211.                 begin
  212.                 NextArg(rest, s1);
  213.                 s := concat(s1, ' is on channels ', rest);
  214.                 Message(s)
  215.             end;
  216.             312: { whois host/server }
  217.                 begin
  218.                 NextArg(rest, s1);
  219.                 s := concat('On IRC via server ', rest);
  220.                 Message(s)
  221.             end;
  222.             317: { whois idle }
  223.                 begin
  224.                 NextArg(rest, s1);
  225.                 NextArg(rest, s2);
  226.                 s := concat('idle for ', s2, ' seconds');
  227.                 Message(s)
  228.             end;
  229.             321: { LIST header }
  230.                 begin
  231.                 NextArg(rest, s1);
  232.                 NextArg(rest, s2);
  233.                 s := StringOf(copy(s1, 1, 12) : 12, s2 : 4, '  ', copy(rest, 1, 60));
  234.                 LineMsg(s);
  235.             end;
  236.             322: { LIST entry }
  237.                 if not flushing then begin
  238.                     NextArg(rest, s1);
  239.                     c := s1[1];
  240.                     if (listpriv and listglob and (c = '*')) or (listpub and ((listloc and (c = '&')) or (listglob and (c = '#')))) then begin
  241.                         NextArg(rest, s2);
  242.                         stringtonum(s2, l);
  243.                         if (l >= listmin) and (l <= listmax) then begin
  244.                             if listtop or (rest <> '') then begin
  245.                                 s := StringOf(copy(s1, 1, 12) : 12, s2 : 4, '  ', copy(rest, 1, 60));
  246.                                 LineMsg(s);
  247.                                 lastWindow := nil; { save from net.terrorists with awfully long topics }
  248.                             end
  249.                         end
  250.                     end
  251.                 end;
  252.             341:  { invite confirmation }
  253.                 begin
  254.                 NextArg(rest, s1);
  255.                 s := concat('Inviting ', s1, ' to channel ', rest);
  256.                 lastInvite := rest;
  257.                 ChannelMsg(rest, s)
  258.             end;
  259.             351: { Server version }
  260.                 begin
  261.                 NextArg(rest, s1);
  262.                 s := concat('Server ', from, ' runs version ', s1);
  263.                 Message(s)
  264.             end;
  265.             367: { Ban list }
  266.                 begin
  267.                 NextArg(rest, s1);
  268.                 s := concat(rest, ' is banned on ', s1);
  269.                 ChannelMsg(s1, s)
  270.             end;
  271.             392, 393: { USERS reply }
  272.                 begin
  273.                 NextArg(rest, s1);
  274.                 NextArg(rest, s2);
  275.                 s := StringOf(copy(s1, 1, 8) : 9, copy(s2, 1, 10) : 12, ' ', rest);
  276.                 LineMsg(s);
  277.             end;
  278.  
  279. { End of list }
  280.             219, 232, 323, 365: { Display it }
  281.                 begin
  282.                 flushing := false;
  283.                 Message(rest);
  284.                 UpdateStatusLine
  285.             end;
  286.             318, 369, 315, 366, 368, 374, 376, 394: { Don't display }
  287.                 begin
  288.                 flushing := false;
  289.                 UpdateStatusLine
  290.             end;
  291.  
  292. { Various errors }
  293.             433: { Nick in use }
  294.                 begin
  295.                 NextArg(rest, s1);
  296.                 s := concat('*** Nickname ', s1, ' is in use. You have to choose another.');
  297.                 LineMsg(s);
  298.             end;
  299.             441: { Not in channel }
  300.                 begin
  301.                 NextArg(rest, s1);
  302.                 NextArg(rest, s2);
  303.                 s := concat('*** ', s1, ' is not on channel ', s2);
  304.                 Message(s);
  305.             end;
  306.             443: { unnecessary invitation }
  307.                 begin
  308.                 NextArg(rest, s1);
  309.                 NextArg(rest, s2);
  310.                 s := concat('*** ', s1, ' is already on channel ', s2);
  311.                 ChannelMsg(s2, s);
  312.             end;
  313.             463, 466: { server refuses connection }
  314.                 begin
  315.                 s := concat('*** ', from, ' refuses connection: ', rest);
  316.                 LineMsg(s)
  317.             end;
  318.  
  319. { messages that generate a response }
  320.             451: { not registered }
  321.                 begin
  322.                 s := concat('*** Registration failed, trying again...');
  323.                 LineMsg(s);
  324.                 RegUser
  325.             end;
  326.             464: { Need password - to be changed }
  327.                 begin
  328.                 s := concat('*** ', rest);
  329.                 LineMsg(s)
  330.             end;
  331.  
  332. { ignored messages }
  333.             2, { duplicated intro }
  334.             300: { dummy }
  335.                 begin
  336.             end;
  337.  
  338.             otherwise
  339.                 NumericComm := false
  340.         end;
  341.     end;
  342.  
  343. end.